export const GetDateStr=(AddCount)=> {
    let dd = new Date();
    dd.setDate(dd.getDate() + AddCount); //获取AddDayCount天后的日期
    let y=dd.getFullYear()<10?'0'+dd.getFullYear():dd.getFullYear();
    let m = dd.getMonth() + 1<10?'0'+(dd.getMonth() + 1):(dd.getMonth() + 1); //获取当前月份的日期
    let d = dd.getDate()<10?'0'+dd.getDate():dd.getDate();
    let getTime=dd.getTime()
let date=`${y}`+'-'+`${m}`+'-'+`${d}`
    return {y,m,d,getTime,date}
  }
// 获取几天的日期数据
export  const GetDate=(num)=>{
    let dateList=[]
    let dateTxt=['今天','明天']
    for(let i=0;i<num;i++){
      const date=GetDateStr(i)
      date.txt=dateTxt[i]
      dateList.push(date)
    }
    return dateList
  }

  /* 时间yyyy-MM-dd HH:mm:ss转为时间戳 */
export const timeToTimestamp=(time)=>{
    let timestamp = Date.parse(new Date(time).toString());
    //timestamp = timestamp / 1000; //时间戳为13位需除1000，时间戳为13位的话不需除1000
    // console.log(time + "的时间戳为：" + timestamp);
    return timestamp;
    //2021-11-18 22:14:24的时间戳为：1637244864707
  }

  // 时间戳：1637244864707
/* 时间戳转换为时间 */
export const timestampToTime=(timestamp)=> {
  timestamp = timestamp ? timestamp : null;
  let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  let Y = date.getFullYear() + '-';
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  return Y + M + D + h + m + s;
}
